package com.example04;
import com.example04.entity.Student;
import com.example04.resource.DatabaseUtils;

import java.util.List;
import java.util.Map;

import static com.example04.service.StudentService.s;

public class Test {
    public static void main(String[] args) {
        //addStudent();
        //listStudentsByYear(2020);
        //listStudentsNames(2021, Student.Sex.FEMALE);
        //listStudentsByYearSortedById(2022);
        //listStudentsMapBySex();
        //listStudentsByYearMapById(2021);
        removeStudent(DatabaseUtils.listStudent(),5);
    }
    private static void forEach(List<Student> s1) {
        for(Student student : s1) {
            System.out.print("ID:" +student.getId() + "   ");
            System.out.print("姓名" + student.getName() + "   ");
            System.out.print("性别:" + student.getSex() + "   ");
            System.out.println("年龄:" + student.getYear() + "   ");
        }
    }

    private static void addStudent() {
        List<Student> s1 = s.addStudent(new Student(7,"唐九",Student.Sex.MALE,2021));
        forEach(s1);
    }

    private static void listStudentsByYear(int year) {
        List<Student> s1 = s.listStudentsByYear(year);
        forEach(s1);
    }
    private static void listStudentsNames(int year, Student.Sex sex) {
        List<String> s1 = s.listStudentsNames(year,sex);
        for(String s : s1) {
            System.out.println("姓名:" +s);
        }
    }
    private static void listStudentsByYearSortedById(int year) {
        List<Student> s1 = s.listStudentsByYearSortedById(year);
        forEach(s1);
    }
    private static void listStudentsMapBySex() {
        Map<Student.Sex, List<Student>> m1 = s.listStudentsMapBySex();
        m1.forEach((k, v) -> {
            System.out.println("key = 性别:" + k);
            for(Student student : v) {
                System.out.print( "  value = ID:" + student.getId() + "   ");
                System.out.print("姓名:" + student.getName() + "   ");
                System.out.println("年龄:" + student.getYear() + "   ");
            }
        });
        /*for(Map.Entry<Student.Sex,List<Student>> entry : m1.entrySet()) {
            System.out.println("key = 性别:" + entry.getKey());
            for(Student student : entry.getValue()) {
                System.out.print( "  value = ID:" + student.getId() + "   ");
                System.out.print("姓名:" + student.getName() + "   ");
                System.out.println("年龄:" + student.getYear() + "   ");
            }
        }*/

    }
    private static void listStudentsByYearMapById(int year) {
        Map<Integer, Student> m1 = s.listStudentsByYearMapById(year);
        m1.forEach((k, v) -> {
            System.out.println("key = ID:" + k);
            System.out.print( "  value =  姓名:" + v.getName() + "   ");
            System.out.print("性别:" + v.getSex() + "   ");
            System.out.println("年龄:" + v.getYear() + "   ");
        });
        /*for(Map.Entry<Integer,Student> entry : m1.entrySet()) {
            System.out.println("key = ID:" + entry.getKey());
            System.out.print( "  value =  姓名:" + entry.getValue().getName() + "   ");
            System.out.print("性别:" + entry.getValue().getSex() + "   ");
            System.out.println("年龄:" + entry.getValue().getYear() + "   ");
        }*/
    }
    private static void removeStudent(List<Student> students, int id) {
        boolean b = s.removeStudent(students,id);
        if(!b) {
            System.out.println("结果:ture");
        }
        else {
            System.out.println("结果:false");
        }
    }
}